package socket;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class Client2 {

    private Socket socket;

    Client2(){
        System.out.println("正在连接服务端。。。");
        try {
            socket = new Socket("176.24.6.36",8088);
            System.out.println("服务端已连接");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public void start() {
        try {
            OutputStream os = socket.getOutputStream();
            PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(os,"UTF-8")),true);
            Scanner scanner = new Scanner(System.in);
            while (true){
                String line = scanner.nextLine();
                pw.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    public static void main(String[] args) {
        Client2 client = new Client2();
        client.start();

    }
}
